package id.co.rho.scoring.cid.client.mvc.login;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.CardLayout;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;

import id.co.rho.scoring.cid.client.mvc.AppView;

import java.util.List;

public class LoginUIWeb implements LoginUI {
    public static final String LOGIN_MASTER_PANEL = "loginMasterPanel";
    public static final String LOGIN_MASTER_LAYOUT = "loginMasterLayout";
    protected LayoutContainer masterPanel;
    protected FormPanel panel;
    protected CardLayout layout;
    private Button btnLogin;
    private TextField<String> userName;
    private TextField<String> passField;

    public LoginUIWeb() {
    }

    @Override
    public void initialize() {
        masterPanel = new LayoutContainer();
        layout = new CardLayout();
        masterPanel.setLayout(layout);
        Registry.register(LOGIN_MASTER_PANEL, masterPanel);
        Registry.register(LOGIN_MASTER_LAYOUT, layout);

        panel = new FormPanel();
        panel.setHeading("Login");
        panel.setBorders(true);
        masterPanel.add(panel);

        userName = new TextField<String>();
        userName.setFieldLabel("Username ");
        panel.add(userName);
        passField = new TextField<String>();
        passField.setFieldLabel("Password");
        passField.setPassword(true);
        panel.add(passField);
        btnLogin = new Button("Login");
        panel.addButton(btnLogin);
    }

    @Override
    public Button getBtnLogin() {
        return btnLogin;
    }

    @Override
    public TextField getUserName() {
        return userName;
    }

    @Override
    public void setUserNameValue(String userName) {
        this.userName.setValue(userName);
    }

    @Override
    public TextField getPassField() {
        return passField;
    }

    @Override
    public void setPassFieldValue(String passField) {
        this.passField.setValue(passField);
    }

    @Override
    public void show() {
        layout.setActiveItem(panel);
    }

    @Override
    public void attach() {
        ContentPanel contentPanel = (ContentPanel) Registry.get(AppView.CENTER_PANEL);
        contentPanel.removeAll();
        contentPanel.setLayout(new FitLayout());
        contentPanel.add(masterPanel);
        contentPanel.layout();
    }

    @Override
    public void load(List data) {
    }

	@Override
	public String getUserNameValue() {
		return userName.getValue();
	}

	@Override
	public String getPassFieldValue() {
		return passField.getValue();
	}
    
    

}
